package com.ly.cloud.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.ly.cloud.common.mybatisplus.plugins.PageInfo;
import com.ly.cloud.dto.ClassInfoDropDownDto;
import com.ly.cloud.dto.ClassInfoDto;
import com.ly.cloud.service.ClassInfoService;
import com.ly.cloud.vo.ClassInfoDropDownVo;
import com.ly.cloud.vo.ClassInfoVo;
import com.ly.cloud.vo.DepartmentVo;
import com.ly.cloud.vo.NjZyTemplateVo;
import com.ly.cloud.web.utils.WebResponse;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description: 班级Controller
 * @Author: pengshiqng
 * @Date: Create in 2018/12/14
 */
@RestController
@RequestMapping("/classInfo")
@Api("班级Controller")
public class ClassInfoController {

    @Autowired
    private ClassInfoService classInfoService ;

    /**
     * 查询所有的年级
     * @return
     */
    @RequestMapping(value = "/findAllGrade", method = RequestMethod.GET)
    public WebResponse<List<String>> findAllGrade() {
        List<String> list = classInfoService.findAllGrade();
        return new WebResponse<List<String>>().success(list);
    }

    /**
     * 根据年级查询所有的学院
     * @param grade
     * @return
     */
    @RequestMapping(value = "/findAllCollegeByGrade", method = RequestMethod.GET)
    public WebResponse<List<DepartmentVo>> findAllCollegeByGrade(@RequestParam String grade) {
        List<DepartmentVo> list = classInfoService.findAllCollegeByGrade(grade);
        return new WebResponse<List<DepartmentVo>>().success(list);

    }

    /**
     * 根据年级+学院查询所有的专业
     * @param grade
     * @param college
     * @return
     */
    @RequestMapping(value = "/findAllProfessional", method = RequestMethod.GET)
    public WebResponse<List<NjZyTemplateVo>> findAllProfessional(@RequestParam String grade, @RequestParam String college) {
        List<NjZyTemplateVo> list = classInfoService.findAllProfessional(grade, college);
        return new WebResponse<List<NjZyTemplateVo>>().success(list);
    }


    /**
     * 分页+条件查询
     */
    @RequestMapping(value = "/queryPageList", method = RequestMethod.POST)
    public WebResponse<PageInfo<ClassInfoVo>> queryPageList(@RequestParam int pageNum, @RequestParam int pageSize, @RequestBody ClassInfoDto dto){
        Page<ClassInfoVo> page = classInfoService.selectPage(new Page<ClassInfoVo>(pageNum, pageSize), dto);
        return new WebResponse<PageInfo<ClassInfoVo>>().success(PageInfo.toPageInfo(page));
    }
    
    /** 
   	 * Method Name: selectDropDownBjxx
   	 * Description:  
   	 * 根据条件查询班级下拉列表
   	 * @param dto 条件封装
   	 * @return 班级下拉列表
   	 * @author luhuacong
   	 * @date: 2018年12月20日
   	 */
    @RequestMapping(value = "/selectDropDownBjxx", method = RequestMethod.POST)
    public WebResponse<List<ClassInfoDropDownVo>> selectDropDownBjxx(@RequestBody ClassInfoDropDownDto dto){
    	List<ClassInfoDropDownVo> voList= classInfoService.selectDropDownBjxx(dto);
    	return new WebResponse<List<ClassInfoDropDownVo>>().success(voList);
    }
    
    /** 
   	 * Method Name: queryById
   	 * Description:  
   	 * 根据班级编号查询班级信息
   	 * @param bjdm 班级代码
   	 * @return 班级信息
   	 * @author luhuacong
   	 * @date: 2018年12月19日
   	 */
    @RequestMapping(value = "/queryById", method = RequestMethod.GET)
    public WebResponse<ClassInfoVo> queryById(@RequestParam String bjdm){
    	ClassInfoVo vo= classInfoService.selectById(bjdm);
    	return new WebResponse<ClassInfoVo>().success(vo);
    }
    
    /** 
   	 * Method Name: selectXzByBjdm
   	 * Description:  
   	 * 根据班级编号查询学制
   	 * @param bjdm 班级代码
   	 * @return 班级的学制
   	 * @author luhuacong
   	 * @date: 2018年12月20日
   	 */
    @RequestMapping(value = "/selectXzByBjdm", method = RequestMethod.GET)
    public WebResponse<Map<String,String>> selectXzByBjdm(@RequestParam String bjdm){
    	Map<String,String> map = classInfoService.selectXzByBjdm(bjdm);
    	return new WebResponse<Map<String,String>>().success(map);
    }

    /**
     * 根据id删除
     */
    @RequestMapping(value = "/deleteById/{bjdm}", method = RequestMethod.POST)
    public WebResponse<Integer> deleteById(@PathVariable("bjdm") String bjdm){
        int result = classInfoService.deleteById(bjdm) ;
        return new WebResponse<Integer>().success(result);
    }

    /**
     * 根据id批量删除
     */
    @RequestMapping(value = "/deleteByIds", method = RequestMethod.POST)
    public WebResponse<Integer> deleteByIds(@RequestBody List<String> ids){
        int result = classInfoService.deleteByIds(ids) ;
        return new WebResponse<Integer>().success(result);
    }

    /**
     * 插入
     */
//    @RequestMapping(value = "/insert", method = RequestMethod.POST)
//    public WebResponse<Boolean> insert(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody ClassInfoDto dto){
//        classInfoService.insert(loginUserName ,dto);
//        return new WebResponse<Boolean>().success(true) ;
//    }
    
    /** 
	 * Method Name: insertBjList
	 * Description:  
	 * 批量创建班级
	 * @param dto
	 * @param loginUserName 创建人
	 * @return 成功创建的班级个数
	 * @author luhuacong
	 * @date: 2018年12月18日
	 */
    @RequestMapping(value = "/insertBjList", method = RequestMethod.POST)
    public WebResponse<Integer> insertBjList(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody List<ClassInfoDto> dtoList){
        Integer count = classInfoService.insertBjList(dtoList, loginUserName);
        return new WebResponse<Integer>().success(count);
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public WebResponse<Boolean> update(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody ClassInfoDto dto){
        classInfoService.uodateById(loginUserName, dto);
        return new WebResponse<Boolean>().success(true) ;
    }

    /** 
	 * Method Name:updateFdyByIdList
	 * Description:  
	 * 批量设置辅导员
	 * @param bjdmLList 班级代码列表
	 * @param fdy 辅导员
	 * @return 成功设置辅导员的班级个数
	 * @author luhuacong
	 * @date: 2018年12月19日
	 */
    @RequestMapping(value = "/updateFdyByIdList", method = RequestMethod.POST)
    public WebResponse<Integer> updateFdyByIdList(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestParam String fdy,@RequestBody List<String> bjdmList){
        Integer count = classInfoService.updateFdyByIdList(bjdmList, fdy, loginUserName);
        return new WebResponse<Integer>().success(count) ;
    }
    
    /** 
	 * Method updateXqByIdList
	 * Description:  
	 * 批量设置班级所属校区
	 * @param bjdmLList 班级代码列表
	 * @param xqdm 校区编号
	 * @param xgr 修改人
	 * @return 成功设置校区的班级个数
	 * @author luhuacong
	 * @date: 2018年12月19日
	 */
    @RequestMapping(value = "/updateXqByIdList", method = RequestMethod.POST)
    public WebResponse<Integer> updateXqByIdList(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestParam String xqdm,@RequestBody List<String> bjdmList){
        Integer count = classInfoService.updateXqByIdList(bjdmList, xqdm, loginUserName);
        return new WebResponse<Integer>().success(count) ;
    }
}
